package unit4;

public class Ex4_6_MethOver {
    public static void main(String[] args) {
        A3 obj1 = new A3();
        B3 obj2 = new B3();
        obj1.setValue();
        obj1.changeValue();
        obj1.print();
        obj2.setValue();
        obj2.changeValue();
        obj2.print();
    }
}
//创建父类A3.
class A3 {
    int i;
    void setValue() {
        i = 100;
    }
    public void changeValue() {
        i = i - 50;
    }
    public void print() {
        System.out.println("父类中i=" + i);
    }
}
//创建类A的子类B3.
class B3 extends A3 {
    int k; //k是子类B3加入的成员变量.
    void setValue() {
        k = 200;
    }
    public void changeValue() {
        k = k + 50;
    }
    public void print() {
        super.print(); //调用父为中的print()方法
        System.out.println("子类中k=" + k);
    }
}
